/**
 * 
 */
package com.primestone.cim.meterreadings.beans;

import java.io.Serializable;

/**
 * @author cesar.mateus
 *
 */
public class Key implements Serializable, Comparable<Key> {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1186608756219662791L;
	
	private String idDeviceOrSocket;
	private String varType;
	
	/**
	 * 
	 */
	public Key() {}

	/**
	 * @param idDeviceOrSocket
	 * @param varType
	 */
	public Key(String idDeviceOrSocket, String varType) {
		super();
		this.idDeviceOrSocket = idDeviceOrSocket;
		this.varType = varType;
	}



	/**
	 * @return the idDeviceOrSocket
	 */
	public String getIdDeviceOrSocket() {
		return this.idDeviceOrSocket;
	}



	/**
	 * @param idDeviceOrSocket the idDeviceOrSocket to set
	 */
	public void setIdDeviceOrSocket(String idDeviceOrSocket) {
		this.idDeviceOrSocket = idDeviceOrSocket;
	}



	/**
	 * @return the varType
	 */
	public String getVarType() {
		return this.varType;
	}



	/**
	 * @param varType the varType to set
	 */
	public void setVarType(String varType) {
		this.varType = varType;
	}



	/**
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((this.idDeviceOrSocket == null) ? 0 : this.idDeviceOrSocket.hashCode());
		result = prime * result
				+ ((this.varType == null) ? 0 : this.varType.hashCode());
		return result;
	}



	/**
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Key other = (Key) obj;
		if (this.idDeviceOrSocket == null) {
			if (other.idDeviceOrSocket != null)
				return false;
		} else if (!this.idDeviceOrSocket.equals(other.idDeviceOrSocket))
			return false;
		if (this.varType == null) {
			if (other.varType != null)
				return false;
		} else if (!this.varType.equals(other.varType))
			return false;
		return true;
	}



	@Override
	public int compareTo(Key o) {
		return 
			new StringBuilder(this.idDeviceOrSocket).append(this.varType).toString().compareTo(
			new StringBuilder(o.idDeviceOrSocket).append(o.varType).toString());
	}



	/**
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("Key [");
		if (this.idDeviceOrSocket != null)
			builder.append("idDeviceOrSocket=").append(this.idDeviceOrSocket).append(", ");
		if (this.varType != null)
			builder.append("varType=").append(this.varType);
		builder.append("]");
		return builder.toString();
	}

}
